{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZQAAABECAYAAACmjMM7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAACPElEQVR4nO3ZMYoTUQDG8ZdNSAJZdr1FzmApeBl7QVAP4DE8glhoIWxn4RFi5xViwJhMMhaxy2ZB/F7eEn6/dhj4qvnPmxn0fV8A4H9dtR4AwGUQFAAiBAWACEEBIGJ06sJ8Pu/KITjL880B4JG7KaXsF4vFUT9OBqUcYjKYTsa31WY1tutaL6irG+1bT6jqerBpPaGa1W7WekJV3XrVekJV09mk9YRqtuuulBNftx4KynI6Gd++fvWiyqjH4PuXyz583T3/0XpCVXdP3reeUM3Tr59bT6jq27tnrSdU9ebjy9YTqvnw9lPZrrt7H57+oQAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkDEoO/7ey/M5/N9KWUwnYzPu+iMdl3rBXV1o33rCVVdDzatJ1Sz2s1aT6iqW69aT6hqOpu0nlDNdt2VUkq/WCyODiSjB+7bl1Ku1r83y1rDqGzXekBdPy/6gP2r9YCqhsNh6wlV/X3oXqqbcujDkZMnFAD4F5f8igfAGQkKABGCAkCEoAAQISgARPwB8K5NVoTYsCUAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 504x72 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import math\n",
    "import matplotlib.ticker as ticker\n",
    "import statsmodels.formula.api as smf\n",
    "from pprint import pprint\n",
    "import re as re\n",
    "\n",
    "from statsmodels.regression.mixed_linear_model import MixedLMResults\n",
    "\n",
    "import scipy as sp\n",
    "#from scipy.stats import nanmean\n",
    "#from scipy.stats import nanstd\n",
    "import copy\n",
    "import scipy.stats as stats\n",
    "import string\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.cm as cm\n",
    "from pprint import pprint\n",
    "import seaborn as sns\n",
    "sns.set(style=\"white\", context=\"talk\")\n",
    "custom_palette = [ \"greyish\", \"dusty purple\", \"greenish\", \"amber\", \"windows blue\", \"black\",\"faded green\"]  \n",
    "                     #\"green blue\", \"dull green\", \"faded green\",  \n",
    "sns.set_palette(sns.xkcd_palette(custom_palette))\n",
    "current_palette = sns.color_palette()\n",
    "%matplotlib inline\n",
    "sns.palplot(current_palette)\n",
    "\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "round_data = pd.read_csv('./all_studies_round_data.csv')\n",
    "\n",
    "round_data['group'] = 1 #this is only for the crossed mixed effect model\n",
    "\n",
    "game_rounds = pd.read_csv('./all_studies_game_data.csv')\n",
    "#round_data = round_data[round_data.round_index > 3]\n",
    "#print(round_data.size)\n",
    "conditions = ['dynamic_full_feedback',\n",
    "              'dynamic',         \n",
    "              'dynamic_self_feedback',\n",
    "              'dynamic_no_feedback',\n",
    "              'static',\n",
    "              'solo_feedback',\n",
    "              'solo_no_feedback'\n",
    "             ]\n",
    "\n",
    "\n",
    "colors ={'dynamic_no_feedback':'#196FFF',\n",
    "         'dynamic_self_feedback':'#000000',\n",
    "         'dynamic_full_feedback':'#E89468',\n",
    "         'dynamic': '#81B200',\n",
    "         'static':'#9B59B6',\n",
    "         'solo_feedback': '#95A5A6',\n",
    "         'solo_no_feedback': '#95A5A6'\n",
    "        }\n",
    "\n",
    "\n",
    "linestyles ={'dynamic_no_feedback':'-.',\n",
    "         'dynamic_self_feedback':':',\n",
    "         'dynamic_full_feedback':'-',\n",
    "         'dynamic': '-',\n",
    "         'static':'--',\n",
    "         'solo_feedback': '-',\n",
    "         'solo_no_feedback': '-'\n",
    "        }\n",
    "\n",
    "markers ={'dynamic_no_feedback':'d',\n",
    "         'dynamic_self_feedback':'^',\n",
    "         'dynamic_full_feedback':'p',\n",
    "         'dynamic': 'o',\n",
    "         'static':'*',\n",
    "         'solo_feedback': 'H',\n",
    "         'solo_no_feedback': 'h'\n",
    "        }\n",
    "\n",
    "#markers = ['s','o','*']\n",
    "#linestyles = ['--','-',':','-.']\n",
    "tick_size = 25\n",
    "label_size = 35\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "studies = [1,2]\n",
    "#crossed model with no independent groups https://stackoverflow.com/questions/50052421/mixed-models-with-two-random-effects-statsmodels\n",
    "# this is used as a variance component for the individual level stuff\n",
    "vcf = {\"player_id\": \"0 + C(player_id)\", \"game_id\": \"0 + C(game_id)\"} \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Table S3: Replication of the Dynamic condition (study 1 vs study 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Table S3: Dynamic condition, study 1 vs Study 2 (individual) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dynamic (study 1) vs dynamic full feedback (study 2): over all\n",
      " β:  -0.0025369739475516215 , t-statistic -0.2630704232807636 , pvalue  0.792496300040277  ci  -0.021438291339704006 0.016364343444600762\n",
      "=============================\n",
      "dynamic (study 1) vs dynamic full feedback (study 2): first half\n",
      " β:  -0.0022982348411483004 , t-statistic -0.2043325204367966 , pvalue  0.8380936583964216  ci  -0.024342975967214447 0.019746506284917847\n",
      "=============================\n",
      "dynamic (study 1) vs dynamic full feedback (study 2): second half\n",
      " β:  -0.0027532272731033854 , t-statistic -0.19754559190727364 , pvalue  0.8434006071138543  ci  -0.030069586218075466 0.024563131671868698\n",
      "=============================\n",
      "dynamic (study 1) vs dynamic full feedback (study 2): adapted periods\n",
      " β:  0.0010566070178353352 , t-statistic 0.11087053337744238 , pvalue  0.9117190124695892  ci  -0.017622041290993613 0.019735255326664283\n"
     ]
    }
   ],
   "source": [
    "#### Study 2 dynamic full feedback vs study 1 dynamic full feedback\n",
    "\n",
    "print(\"dynamic (study 1) vs dynamic full feedback (study 2): over all\")\n",
    "forumla = \"revised_error ~ C(condition, Treatment('dynamic'))\"\n",
    "data = round_data[(round_data.condition.isin(['dynamic_full_feedback','dynamic'])) &  (round_data.revised_error.notnull())]\n",
    "model = smf.mixedlm(forumla,data=data,groups='group',\n",
    "                    vc_formula=vcf,re_formula=\"0\").fit(method='powell')\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], ' ci ', model.conf_int()[0][1], model.conf_int()[1][1])#print (' ---- ')\n",
    "#print(model.summary())\n",
    "\n",
    "print('=============================')\n",
    "\n",
    "\n",
    "print(\"dynamic (study 1) vs dynamic full feedback (study 2): first half\")\n",
    "\n",
    "forumla = \"revised_error ~ C(condition, Treatment('dynamic'))\"\n",
    "data = round_data[\n",
    "                  (round_data.condition.isin(['dynamic_full_feedback','dynamic'])) &\n",
    "                  (round_data.half==1) &  (round_data.revised_error.notnull())\n",
    "                 ]\n",
    "model = smf.mixedlm(forumla,data=data,groups='group',\n",
    "                    vc_formula=vcf,re_formula=\"0\").fit(method='powell')\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], ' ci ', model.conf_int()[0][1], model.conf_int()[1][1])#print (' ---- ')\n",
    "#print(model.summary())\n",
    "\n",
    "print('=============================')\n",
    "\n",
    "print(\"dynamic (study 1) vs dynamic full feedback (study 2): second half\")\n",
    "\n",
    "forumla = \"revised_error ~ C(condition, Treatment('dynamic'))\"\n",
    "data = round_data[\n",
    "                  (round_data.condition.isin(['dynamic_full_feedback','dynamic'])) &\n",
    "                  (round_data.half==2) &  (round_data.revised_error.notnull())\n",
    "                 ]\n",
    "model = smf.mixedlm(forumla,data=data,groups='group',\n",
    "                    vc_formula=vcf,re_formula=\"0\").fit(method='powell')\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], ' ci ', model.conf_int()[0][1], model.conf_int()[1][1])#print (' ---- ')\n",
    "#print(model.summary())\n",
    "\n",
    "\n",
    "print('=============================')\n",
    "\n",
    "print(\"dynamic (study 1) vs dynamic full feedback (study 2): adapted periods\")\n",
    "forumla = \"revised_error ~ C(condition, Treatment('dynamic'))\"\n",
    "data = round_data[\n",
    "                  (round_data.condition.isin(['dynamic_full_feedback','dynamic'])) &\n",
    "                  (round_data.quarter.isin([2,4])) &  (round_data.revised_error.notnull())\n",
    "                 ]\n",
    "model = smf.mixedlm(forumla,data=data,groups='group',\n",
    "                    vc_formula=vcf,re_formula=\"0\").fit(method='powell')\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], ' ci ', model.conf_int()[0][1], model.conf_int()[1][1])#print(model.summary())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Table S3: Dynamic condition, study 1 vs Study 2 (group) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dynamic (study 1) vs dynamic full feedback (study 2): over all\n",
      " β:  0.0009102591390089572 , t-statistic 0.09069857110011698 , pvalue  0.9277321060501107  ci  -0.018760118325776634 0.02058063660379455\n",
      "=============================\n",
      "dynamic (study 1) vs dynamic full feedback (study 2): first half\n",
      " β:  -0.0030158369408370095 , t-statistic -0.26223654028974636 , pvalue  0.7931390837485541  ci  -0.02555629518801712 0.0195246213063431\n",
      "=============================\n",
      "dynamic (study 1) vs dynamic full feedback (study 2): second half\n",
      " β:  0.004836355218855029 , t-statistic 0.3327405974310441 , pvalue  0.7393301017122742  ci  -0.02365154832697724 0.033324258764687295\n",
      "=============================\n",
      "dynamic (study 1) vs dynamic full feedback (study 2): adapted periods\n",
      " β:  0.0040646632996632565 , t-statistic 0.41185842468171013 , pvalue  0.6804431953839256  ci  -0.015278375956553035 0.023407702555879546\n"
     ]
    }
   ],
   "source": [
    "#### Study 2 dynamic full feedback vs study 1 dynamic full feedback\n",
    "\n",
    "print(\"dynamic (study 1) vs dynamic full feedback (study 2): over all\")\n",
    "forumla = \"revised_wisdom_error ~ C(condition, Treatment('dynamic'))\"\n",
    "data = game_rounds[(game_rounds.condition.isin(['dynamic_full_feedback','dynamic']))]\n",
    "model = smf.mixedlm(forumla,data=data,groups=data['game_id']).fit(method='powell')\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], ' ci ', model.conf_int()[0][1], model.conf_int()[1][1])#print (' ---- ')\n",
    "#print(model.summary())\n",
    "\n",
    "print('=============================')\n",
    "\n",
    "\n",
    "print(\"dynamic (study 1) vs dynamic full feedback (study 2): first half\")\n",
    "\n",
    "forumla = \"revised_wisdom_error ~ C(condition, Treatment('dynamic'))\"\n",
    "data = game_rounds[\n",
    "                  (game_rounds.condition.isin(['dynamic_full_feedback','dynamic'])) &\n",
    "                  (game_rounds.half==1)\n",
    "                 ]\n",
    "model = smf.mixedlm(forumla,data=data,groups=data['game_id']).fit(method='powell')\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], ' ci ', model.conf_int()[0][1], model.conf_int()[1][1])#print (' ---- ')\n",
    "#print(model.summary())\n",
    "\n",
    "print('=============================')\n",
    "\n",
    "print(\"dynamic (study 1) vs dynamic full feedback (study 2): second half\")\n",
    "\n",
    "forumla = \"revised_wisdom_error ~ C(condition, Treatment('dynamic'))\"\n",
    "data = game_rounds[\n",
    "                  (game_rounds.condition.isin(['dynamic_full_feedback','dynamic'])) &\n",
    "                  (game_rounds.half==2)\n",
    "                 ]\n",
    "model = smf.mixedlm(forumla,data=data,groups=data['game_id']).fit(method='powell')\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], ' ci ', model.conf_int()[0][1], model.conf_int()[1][1])#print (' ---- ')\n",
    "#print(model.summary())\n",
    "\n",
    "\n",
    "print('=============================')\n",
    "\n",
    "print(\"dynamic (study 1) vs dynamic full feedback (study 2): adapted periods\")\n",
    "forumla = \"revised_wisdom_error ~ C(condition, Treatment('dynamic'))\"\n",
    "data = game_rounds[\n",
    "                  (game_rounds.condition.isin(['dynamic_full_feedback','dynamic'])) &\n",
    "                  (game_rounds.quarter.isin([2,4]))\n",
    "                 ]\n",
    "model = smf.mixedlm(forumla,data=data,groups=data['game_id']).fit(method='powell')\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], ' ci ', model.conf_int()[0][1], model.conf_int()[1][1])#print(model.summary())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
